package test1;

import java.util.List;
import java.util.Random;

public class SentThread extends Thread {
    private int count = 0;
    private List<String> gift;

    public SentThread(List<String> gift, String name) {
        super(name);
        this.gift = gift;
    }

    @Override
    public void run() {
        String names = Thread.currentThread().getName();
        //小红小明 送礼物
        Random r = new Random();
        while (true) {
            synchronized (gift) {
                //有一个人进来了
                if(gift.size() < 10){
                    break;

                }

                gift.remove(r.nextInt(gift.size()));
                System.out.println(getName() + "送出礼物：" + gift.get(r.nextInt(gift.size())));
                count++;
            }
        }

    }


    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}
